const values_default = {
  //  type: 'contact'
}

const domain_default = {}

const fields_default = {
  name: null,
  login: null,
  email: null,
  company_id: null,
  company_ids: { name: null, display_name: null }
}

const filterItems = [
  { type: 'input', name: 'name___like', placeholder: '名称' },
  { type: 'select', name: 'company_id', placeholder: '公司' }
]

const columns = [
  { name: 'login', type: 'char', label: '账号' },
  { name: 'name', type: 'char', label: '名称' },
  { name: 'email', type: 'char', label: '邮箱' },
  { name: 'company_id__name', type: 'char', label: '公司' },
  { name: 'company_ids__names', type: 'char', label: '我管理的所有公司' }
]

const formItems = [
  { type: 'input', name: 'name', label: '名称' },
  { type: 'input', name: 'login', label: '账号' },
  { type: 'input', name: 'email', label: '邮箱' },
  {
    type: 'select',
    name: 'company_id',
    label: '公司',
    placeholder: '公司',

    // options : undefined,  无需初始化 options_for_select
    options: undefined,

    options_for_select: params => {
      const { self, temp, items } = params
      // console.log('xxxxxxxx,self,', self)
      return items.company_ids.options_for_select_init.filter(item =>
        temp.company_ids.includes(item.id)
      )
    }
  },
  {
    type: 'select',
    name: 'company_ids',
    label: '公司s',
    placeholder: '公司s',
    multiple: true,
    default: []
  }
]

const child_configs = {}

const Model = {
  name: 'res.users',
  configs: {
    values_default,
    domain_default,
    fields_default,
    filterItems,
    columns,
    formItems,
    child_configs
  },

  extend: BaseClass => {
    class ModelClass extends BaseClass {
      async search(query) {
        const ss = await super.search(query)
        return ss
      }
      global_domain(domain_src = {}) {
        const domain = { ...domain_src }
        // const userinfo = self.get_userinfo()
        // const { uid } = userinfo
        // domain.user_id = uid
        return super.global_domain(domain)
      }

      change_password(old_passwd, new_passwd) {
        console.log('odoo. res.users, change_password,', old_passwd, new_passwd)
        return this.call('change_password', [old_passwd, new_passwd])
      }
    }
    return ModelClass
  }
}

export default Model
